package com.cily.utils.t_webrtc.singlr.phone;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.cily.utils.app.event.Event;
import com.cily.utils.t_webrtc.BaseAc;
import com.cily.utils.t_webrtc.BaseAc3;
import com.cily.utils.t_webrtc.R;
import com.cily.utils.t_webrtc.singlr.Beans.CurrentUser;
import com.cily.utils.t_webrtc.singlr.Beans.MessageBean;
import com.cily.utils.t_webrtc.singlr.Services.ActionMessageService;
import com.cily.utils.t_webrtc.singlr.Services.SignalRService;

public class LoginActivity extends BaseAc3 {
    private EditText et_user_name;
    private EditText et_password;
    private String roomNumber = "111";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        et_user_name = (EditText)findViewById(R.id.edit_user_name_id);
        et_password = (EditText)findViewById(R.id.edit_password_id);

        findBtn(R.id.btn_login_id).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //发生登录信息
                SignalRService.mConnection.send(ActionMessageService.login(et_user_name.getText().toString(),roomNumber));

            }
        });

        findBtn(R.id.btn_to_register_id).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                toAc(RegisterActivity.class, null);
            }
        });
    }



    @Override
    protected void onDestroy() {
        super.onDestroy();
    }


    @Override
    public void doEvent(Event e) {
        MessageBean messageBean = (MessageBean)e.obj;
        if(messageBean != null) {
            int code = messageBean.getCode();
            if(code == 1) {
                CurrentUser.setCUser(messageBean.getSender());
                toAc(ProfileActivity.class, null);
            }
        }
    }
}
